var columns = [
    {
        field: 'id', title: '序号',
        formatter: function (value, row, index) {
            return index + 1 + (row.pageNumber - 1) * row.pageSize;
        }
    },
    //{field: 'id',title: '序号'},
    {field: 'cateName', title: '分类名称'},
    {field: 'cateType', title: '分类类型'},
    {field: 'sn', title: '序号'},
    {field: 'level', title: '层级'},
    {field: 'parentName', title: '父级名称'},
    {
        field: 'state', title: '是否启用', class: 'col-width-state',
        align: 'center',
        formatter: function (value, row, index) {
            return pubSwitch.getSwitchBtnCss(row);
        }
    },
    {
        field: 'operator', title: '操作',
        formatter: function (value, row, index) {
            return pubOptBtn.getOptBtn('category',menu,row.id);
        }
    }];

var category = {
    init: function () {
        var qryCategoryName = $("#qryCategoryName").val();
        var qryCategoryType = $("#qryCategoryType").val();
        var parmsObj = {};
        parmsObj.qryCategoryName=qryCategoryName;
        parmsObj.qryCategoryType=qryCategoryType;
        pubForm.getBootTableSwitch("#tableCategoryList", "/category/queryCategoryList?qryCategoryName="+qryCategoryName+"&qryCategoryType="+qryCategoryType, "/base/switch/updateState", parmsObj, "t_category");
    },
    showOperationPage: function (categoryId) {
        loadUtil = new Load($);
        loadUtil.load({
            container: '#homeContent',
            url: application.contextPath + "/category/showOperationPage?categoryId=" + categoryId+"&menuId="+menuId
        });
    },
    showSCategoryPage: function (categoryId) {
        loadUtil = new Load($);
        loadUtil.load({
            container: '#homeContent',
            url: application.contextPath + "/category/showSCategoryPage?categoryId=" + categoryId+"&menuId="+menuId
        });
    },
    refreshTabel: function () {
        var qryCategoryName = $("#qryCategoryName").val();
        var qryCategoryType = $("#qryCategoryType").val();
        var opt = {
            url: application.contextPath + "/category/queryCategoryList",
            query: {size: 5, page: 1,qryCategoryName:qryCategoryName,qryCategoryType:qryCategoryType},
            silent: true
        };
        $("#tableCategoryList").bootstrapTable('refreshOptions',opt);
    },
    delCategory: function (categoryId) {
        layer.confirm('确定要删除嘛?', {
            icon: 7, title: '删除提示', btn: ['是', '否'],
            yes: function (index, layero) {
                $.ajax({
                    url: application.contextPath + "/category/delCategory",
                    type: "POST",
                    dataType: "json",
                    data: {
                        "id": categoryId
                    },
                    success: function (res) {
                        if ("1" == res.data) {
                            var qryCategoryName = $("#qryCategoryName").val();
                            var qryCategoryType = $("#qryCategoryType").val();
                            var opt = {
                                url: application.contextPath + "/category/queryCategoryList",
                                query: {size: 5, page: 1,qryCategoryName:qryCategoryName,qryCategoryType:qryCategoryType},
                                silent: true
                            };
                            $('#tableCategoryList').bootstrapTable('refresh', opt);
                            layer.msg('删除成功', {icon: 1})
                        }
                    }
                });
            }, function() {
                layer.close(layer.index);
            }
        });
    },
    queryCategoryByTypeOrTypeName: function () {
        var size = $(".page-size").text();
        var qryCategoryName = $("#qryCategoryName").val();
        var qryCategoryType = $("#qryCategoryType").val();
        var opt = {
            url: application.contextPath + "/category/queryCategoryByTypeOrTypeName?qryCategoryName="+qryCategoryName+"&qryCategoryType="+qryCategoryType,
            query: {
                size: size,
                page: 1
            },
            silent: true
        };
        $('#tableCategoryList').bootstrapTable('refreshOptions', opt);

    },
    //打开添加页面
    showAddCategoryPage: function () {
        loadUtil = new Load($);
        loadUtil.load({
            container: '#homeContent',
            url: application.contextPath + "/category/showCategoryAddPage?menuId="+menuId,
        });
    },
    showCategoryUpdatePage: function (id) {
        loadUtil = new Load($);
        loadUtil.load({
            container: '#homeContent',
            url: application.contextPath + "/category/showCategoryUpdatePage?categoryId=" + id+"&menuId="+menuId,
        });
    }
};

$(document).ready(function () {
    category.init();
});